<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>评论管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/x-admin/font.css">
    <link rel="stylesheet" href="/static/css/x-admin/xadmin.css">
    <link rel="stylesheet" href="/static/css/admin-index.css">
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a>控制台</a>
        <a>文章管理</a>
        <a><cite>评论管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-sm layui-btn-radius" style="line-height:1.6em;margin-top:4px;float:right"
       href="javascript:location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-anim layui-anim-scale x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" action="/admin/comment/showComments">
            <div class="layui-inline">
                <label for="title">评论内容：</label>
                <div class="layui-inline">
                    <input id="content" type="text" name="commContent" placeholder="输入关键字"
                           class="layui-input"
                           value="<#if commContent??>${commContent}</#if>">
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn" lay-submit lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
            </div>
        </form>
    </div>
    <table class="layui-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>名称</th>
            <th>文章</th>
            <th>内容</th>
            <th>IP</th>
            <th>邮箱</th>
            <th>日期</th>
            <th>状态</th>
            <th>操作</th>
        </thead>
        <tbody>
            <#list allComment as comm>
            <tr>
                <td>${comm.getArticleId()}</td>
                <td><a <#if comm.getCommAuthorUrl()??>href="${comm.getCommAuthorUrl()}"
                       target="_blank" </#if>>${comm.getCommAuthorName()}<i class="layui-icon layui-icon-link"></i></a>
                </td>
                <td>${comm.getArticleTitle()}</td>
                <td>${comm.getCommContent()}</td>
                <td>${comm.getCommAuthorIp()}</td>
                <td><#if comm.getCommAuthorEmail()??>${comm.getCommAuthorEmail()}<#else>无</#if></td>
                <td class="td-status">${comm.getCommDate()?string('yyyy-MM-dd HH:mm:ss')}</td>
                <td class="td-status">
                    <#if comm.getCommStatus() == 0>
                        <span class="layui-btn layui-bg-cyan layui-btn-xs">审核</span>
                    <#elseif comm.getCommStatus() == 1>
                        <span class="layui-btn layui-btn-xs">通过</span>
                    </#if>
                </td>
                <td class="td-manage">
                    <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del(this, ${comm.getCommId()})">
                        删除
                    </button>
                    <#if comm.getCommStatus() == 1>
                        <button class="layui-btn layui-bg-cyan layui-btn-xs"
                                onclick="update_comm(this, ${comm.getCommId()}, 0)">
                            更改为审核
                        </button>
                    <#elseif comm.getCommStatus() == 0>
                        <button class="layui-btn layui-btn-xs" onclick="update_comm(this, ${comm.getCommId()}, 1)">
                            更改为通过
                        </button>
                    </#if>
                </td>
            </tr>
            </#list>
        </tbody>
    </table>
    <!-- 分页 -->
    <div class="layui-box layui-laypage layui-laypage-default">
        <#if !pageInfo.isFirstPage>
                <a href="/admin/comment/showComments?pageNum=${pageInfo.firstPage}&pageSize=${pageInfo.pageSize}<#if commContent??>&commContent=${commContent}</#if>"
                   class="layui-laypage-next">首页</a>
        <#elseif pageInfo.isFirstPage>
            <a class="layui-laypage-next layui-disabled">首页</a>
        </#if>
        <#if pageInfo.hasPreviousPage>
            <a href="/admin/comment/showComments?pageNum=${pageInfo.prePage}&pageSize=${pageInfo.pageSize}<#if commContent??>&commContent=${commContent}</#if>"
               class="layui-laypage-prev ">上一页</a>
        <#elseif !pageInfo.hasPreviousPage>
            <a class="layui-laypage-prev layui-disabled">上一页</a>
        </#if>

         <#list pageInfo.navigatepageNums as nav>
             <#if nav == pageInfo.pageNum>
                 <span class="layui-laypage-curr"><em class="layui-laypage-em"></em><em>${nav}</em></span>
             </#if>
             <#if nav != pageInfo.pageNum>
                 <a href="/admin/comment/showComments?pageNum=${nav}&pageSize=${pageInfo.pageSize}<#if commContent??>&commContent=${commContent}</#if>">${nav}</a>
             </#if>
         </#list>
        <#if pageInfo.hasNextPage>
            <a href="/admin/comment/showComments?pageNum=${pageInfo.nextPage}&pageSize=${pageInfo.pageSize}<#if commContent??>&commContent=${commContent}</#if>"
               class="layui-laypage-next">下一页</a>
        </#if>
        <#if !pageInfo.hasNextPage>
            <a class="layui-laypage-next layui-disabled">下一页</a>
        </#if>
        <#if !pageInfo.isLastPage>
            <a href="/admin/comment/showComments?pageNum=${pageInfo.lastPage}&pageSize=${pageInfo.pageSize}<#if commContent??>&commContent=${commContent}</#if>"
               class="layui-laypage-next">尾页</a>
        </#if>
        <#if pageInfo.isLastPage>
            <a class="layui-laypage-next layui-disabled">尾页</a>
        </#if>
    </div>
</div>
<script type="text/javascript" src="/static/js/jquery/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/static/js/x-admin/xadmin.js"></script>
<script type="text/javascript">
    /*删除*/
    function del(obj, id) {
        layer.confirm('确认要删除吗？', {
            icon: 3,
            anim: 2
        }, function () {
            $.ajax({
                url: "/admin/comment/deleteComment",
                data: {
                    commId: id
                },
                type: "post",
                success: function (data) {
                    if (data.code === 2005) {
                        $(obj).parents("tr").remove();
                        layer.msg(data.message, {
                            icon: 1, time: 1000,
                            anim: 2
                        });
                    } else {
                        layer.msg(data.message, {
                            icon: 5, time: 1000,
                            anim: 2
                        });
                    }
                },
                error: function () {
                    layer.msg('删除评论失败!', {
                        icon: 5, time: 1000,
                        anim: 2
                    });
                }
            });
        });
    }

    /*更新评论状态*/
    function update_comm(obj, id, status) {
        var tips = '确定要更改为审核中吗？';
        if (status === 1) {
            tips = '确定要更改为审核通过吗';
        }
        layer.confirm(tips, {
            icon: 3,
            anim: 2
        }, function () {
            $.ajax({
                url: "/admin/comment/updateCommStatus",
                data: {
                    commId: id,
                    commStatus: status
                },
                type: "post",
                success: function (data) {
                    if (data.code === 2006) {
                        layer.msg(data.message, {
                            icon: 1, time: 1000,
                            anim: 2
                        }, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.message, {
                            icon: 5, time: 1000,
                            anim: 2
                        }, function () {
                            window.location.reload();
                        });
                    }
                },
                error: function () {
                    layer.msg('更新评论状态失败!', {
                        icon: 5, time: 1000,
                        anim: 2
                    });
                }
            });
        });
    }
</script>
</body>
</html>